<template>
    <div>
        <el-form :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="项目编号" prop="ProjectCode">
                <el-input v-model="model.ProjectCode"></el-input>
            </el-form-item>

            <el-form-item label="项目名称" prop="ProjectName">
                <el-input v-model="model.ProjectName"></el-input>
            </el-form-item>

            <el-form-item label="分类" prop="Classify">
                <el-select v-model="model.Classify" placeholder="请选择分类">
                    <el-option v-for="item in QcProjectClassifyList" :key="item.Id" :label="item.ProjectName"
                    :value="item.ProjectName"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="检测器具" prop="Device">
                <el-select v-model="model.Device" placeholder="请选择检测器具">
                    <el-option v-for="item in QcProjectDeviceList" :key="item.Id" :label="item.DeviceName"
                    :value="item.DeviceName"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="标准数值" prop="StandValue">
                <el-input v-model="model.StandValue"></el-input>
            </el-form-item>

            <el-form-item label="标准单位" prop="StandUnit">
                <el-select v-model="model.StandUnit" placeholder="请选择标准单位">
                    <el-option v-for="item in UnitMeasureList" :key="item.Id" :label="item.MeasureName"
                    :value="item.MeasureName"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="描述" prop="Remark">
                <el-input v-model="model.Remark"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>


export default {
    props: {
        model:{
            require:true,
            type: Object
        },
        isUpdate: {
            require: true,
            type: Boolean
        }
    },
    data(){
        return{
            
            QcProjectDeviceList:[],
            UnitMeasureList:[],
            QcProjectClassifyList:[],
            rules:{
                ProjectCode:{required: true,message: '请输入编号',trigger: 'blur'},
                ProjectName:{required: true,message: '请输入名称',trigger: 'blur'},
                Classify:{required: true,message: '请选择分类 ',trigger: 'blur'},
                Device:{required: true,message: '请选择检测器具',trigger: 'blur'},
                StandValue:{required: true,message: '请输入标准数值',trigger: 'blur'},
                StandUnit:{required:true,message:'请选择标准单位',trigger:'blur'},
                Creator:{required:true,message:'请输入创建者',trigger:'blur'},
            },
        }
    },
    created(){
        this.getUnitMeasureData();
        this.getQcProjectDeviceData();
        this.getQcProjectClassifyData();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid) => {
                if (valid){
                    if(this.isUpdate)
                    {
                        this.put();
                    }
                    else{
                        this.add();
                    }
                }
                else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm(){
            this.$refs['ruleForm'].resetFields();
        },
        add(){
            this.$http.postForm('./api/QcProject',{model:this.model},{loading:this.$loading()})
            .then((res=>{
                this.$emit('callback');
            }))
        },
        put(){
        this.$http.putForm('/api/QcProject',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
      },
        getUnitMeasureData(){
        this.$http.get('/api/UnitMeasure/GetAll')
        .then(res=>{
            this.UnitMeasureList=res.Data;
        })
      },
      getQcProjectDeviceData(){
        this.$http.get('/api/QcProjectDevice/GetAll')
        .then(res=>{
            this.QcProjectDeviceList=res.Data;
        })
      },
      getQcProjectClassifyData(){
        this.$http.get('/api/QcProjectClassify/GetAll')
        .then(res=>{
            this.QcProjectClassifyList=res.Data;
        })
      }
    }

}

</script>
<style></style>